package com.blog.controller.frontpage;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blog.controller.base.BaseServlet;
import com.blog.entity.UserLoginEntity;
import com.blog.service.frontpage.PersonalCenterService;

@WebServlet("/userinfoupdate")
public class UpdateUserInfoServlet extends BaseServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		UserLoginEntity user=(UserLoginEntity )req.getSession().getAttribute("user");
		int userid=user.getUser_id();
		PersonalCenterService service=PersonalCenterService.getInstance();
		String user_name=req.getParameter("user_name");
		String user_password=req.getParameter("user_password");
		String user_phone=req.getParameter("user_phone");
		String user_word=req.getParameter("user_word");
		if(user_name!=null&&!user_name.equals("")) {
			service.updateUserInfo("user_name", user_name, userid);
		}
		if(user_password!=null&&!user_password.equals("")) {
			service.updateUserInfo("user_password", user_password, userid);
		}
		if(user_phone!=null&&!user_phone.equals("")) {
			service.updateUserInfo("user_phone", user_phone, userid);
		}
		if(user_word!=null&&!user_word.equals("")) {
			service.updateUserInfo("user_word", user_word, userid);
		}
		resp.getWriter().println("修改成功");
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
}